//
//  RewardPopVC.m
//  LoveTrail
//
//  Created by giantumbrella on 15/6/12.
//  Copyright (c) 2015年 赵娟. All rights reserved.
//

#import "RewardPopVC.h"
#import "AppDelegate.h"

@interface RewardPopVC ()

@end

@implementation RewardPopVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
}

-(void)popRewardView
{
    //window 上添加一个视图
    //window上添加内容视图
    UIWindow *window=[[UIApplication sharedApplication].delegate window];
    UIView *aview=[[UIView alloc]initWithFrame:[UIScreen mainScreen].bounds];
    aview.backgroundColor=[UIColor blackColor];
    aview.tag=100;
    aview.alpha=0.3;
    
    [window addSubview:aview];
    UIView *bview=[[UIView alloc]init];
    bview.tag=101;
    bview.layer.cornerRadius=5;
    bview.frame=CGRectMake(40, window.frame.size.height, window.frame.size.width-40, window.frame.size.height/1.5f);
//    bview.backgroundColor = [UIColor blueColor];
    [window addSubview:bview];
    [self addSubViews];
 
    //给bview一个动画
    [UIView animateWithDuration:0.5 animations:^{
        bview.center=window.center;
    }];
    
}


//给bview添加子视图
-(void)addSubViews{
    UIWindow *window=[[UIApplication sharedApplication].delegate window];
    UIView *bview=[window viewWithTag:101];
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(bview.frame.size.width*0.1, 0.0, bview.frame.size.width*0.8, bview.frame.size.height*0.65)];
    imageView.image = [UIImage imageNamed:@"签到弹窗@2x"];
    [bview addSubview:imageView];
    
    //添加一个按钮
    UIButton *backButton = [[UIButton alloc] initWithFrame:CGRectMake(imageView.frame.size.width*0.3, imageView.frame.origin.y+imageView.frame.size.height+10, imageView.frame.size.width*0.75, imageView.frame.size.height*0.17)];
    [backButton setBackgroundImage:[UIImage imageNamed:@"返回"] forState:UIControlStateNormal];
    [backButton setBackgroundImage:[UIImage imageNamed:@"返回-选中后"] forState:UIControlStateHighlighted];
    [bview addSubview:backButton];
    [backButton addTarget:self action:@selector(dimiss:) forControlEvents:UIControlEventTouchUpInside];
}

//点击保存按钮后退出当前页面
-(void)dimiss:(id)sender{
    UIWindow *window=[[UIApplication sharedApplication].delegate window];
    UIView *aview=[window viewWithTag:100];
    UIView *bview=[window viewWithTag:101];
    
    [UIView animateWithDuration:0.5 animations:^{
        bview.frame=CGRectMake(0, -120, window.frame.size.width, 60);
    } completion:^(BOOL finished) {
        [bview removeFromSuperview];
        [aview removeFromSuperview];
    }];
}

@end
